import pandas as pd
import ast
import statistics

df = pd.read_csv('training_merge_3ap.csv')

def parse_array_generator(f):
    def ret(value):
        value = str(value)
        if value.isnumeric():
            return value
        elif value.startswith('['):
            a = ast.literal_eval(value)
            return f(a)
        else:
            return ''
    return ret

for colName in df.columns:
    if 'max' in colName:
        print('max', colName)
        df[colName] = df[colName].apply(parse_array_generator(max))
    elif 'sum' in colName:
        print('sum', colName)
        df[colName] = df[colName].apply(parse_array_generator(sum))
    elif 'mean' in colName:
        print('mean', colName)
        df[colName] = df[colName].apply(parse_array_generator(statistics.mean))
    elif 'sta_' in colName:
        print('other', colName)
        df[colName] = df[colName].apply(parse_array_generator(statistics.mean))

df.to_csv('reduceRssi_3ap.csv')
